package com.cskaoyan.controller.mall;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.PageDataVo;
import com.cskaoyan.bean.mall.keyword.Keyword;
import com.cskaoyan.service.mall.KeywordService;
import com.cskaoyan.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 商场管理模块——关键词
 * @author: enhui
 **/
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {
    @Autowired
    KeywordService keywordService;

    @RequestMapping("list")
    public BaseRespVo keywordList(String keyword, String url, BaseParam param) {
        PageDataVo basePageData = keywordService.keywordList(keyword, url, param);
        if (basePageData == null) {
            return BaseRespVo.error();
        }
        return BaseRespVo.ok(basePageData);
    }

    @RequestMapping("create")
    public BaseRespVo createKeyword(@RequestBody Keyword keyword) {
        Keyword keywordCreate = keywordService.createKeyword(keyword);
        if (keywordCreate == null) {
            return BaseRespVo.error("新建关键字失败");
        }
        return BaseRespVo.ok(keywordCreate);
    }

    @RequestMapping("update")
    public BaseRespVo updateKeyword(@RequestBody Keyword keyword) {
        Keyword keywordUpdate = keywordService.updateKeyword(keyword);
        if (keywordUpdate == null) {
            return BaseRespVo.error("更新关键字失败");
        }
        return BaseRespVo.ok(keywordUpdate);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteKeyword(@RequestBody Keyword keyword) {
        int code = keywordService.deleteKeyword(keyword);
        if (code == Constant.SUCCESS) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error("删除关键字失败");
    }
}
